package com.zmc.lostfound.system.controller;

import com.zmc.lostfound.common.utils.PageResult;
import com.zmc.lostfound.common.utils.Result;
import com.zmc.lostfound.common.valid.AddGroup;
import com.zmc.lostfound.common.valid.UpdateGroup;
import com.zmc.lostfound.system.entity.FeedbackEntity;
import com.zmc.lostfound.system.service.FeedbackService;
import com.zmc.lostfound.system.vo.FeedbackQueryVO;
import com.zmc.lostfound.system.vo.FeedbackSaveVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZMC
 * @description 反馈信息管理接口
 * @email 2869581855@qq.com
 */
@RestController
@RequestMapping("/feedback")
@Api(value = "反馈信息管理接口", tags = "反馈信息管理接口")
public class FeedbackController {

    private final FeedbackService feedbackService;

    public FeedbackController(FeedbackService feedbackService) {
        this.feedbackService = feedbackService;
    }

    @ApiOperation("多条件查询用户反馈信息")
    @GetMapping("/query/page")
    public Result queryPage(@Validated FeedbackQueryVO feedbackQueryVO) {
        PageResult pageResult = feedbackService.queryPage(feedbackQueryVO);
        return Result.ok("查询成功").put("pageResult", pageResult);
    }

    @ApiOperation("按主键id查询用户反馈信息")
    @GetMapping("/query/infoById/{id}")
    public Result queryInfoById(@PathVariable("id") Long id) {
        FeedbackEntity feedbackInfo = feedbackService.queryInfoById(id);
        return Result.ok("查询成功").put("feedbackInfo", feedbackInfo);
    }

    @ApiOperation("新增用户反馈信息")
    @PostMapping("/insertFeedback")
    public Result insertFeedback(@RequestBody @Validated(value = {AddGroup.class}) FeedbackSaveVO feedbackSaveVO) {
        return feedbackService.insertFeedback(feedbackSaveVO);
    }

    @ApiOperation("修改用户反馈信息")
    @PutMapping("/updateFeedback")
    public Result updateFeedback(@RequestBody @Validated(value = {UpdateGroup.class}) FeedbackSaveVO feedbackSaveVO) {
        return feedbackService.updateFeedback(feedbackSaveVO);
    }

    @ApiOperation("按反馈ids批量删除用户反馈信息")
    @DeleteMapping("/deleteBatchByIds")
    public Result deleteBatchByIds(@RequestBody List<Long> ids) {
        return feedbackService.deleteBatchByIds(ids);
    }

    @ApiOperation("按用户id批量删除用户反馈信息")
    @DeleteMapping("/deleteBatchByUserId/{userId}")
    public Result deleteBatchByUserId(@PathVariable("userId") Long userId) {
        return feedbackService.deleteByUserIdAndFunctionId(userId, null);
    }

    @ApiOperation("按系统功能id批量删除用户反馈信息")
    @DeleteMapping("/deleteBatchByFunctionId/{functionId}")
    public Result deleteBatchByFunctionId(@PathVariable("functionId") Long functionId) {
        return feedbackService.deleteByUserIdAndFunctionId(null, functionId);
    }

    @ApiOperation("按用户id和系统功能id删除用户反馈信息")
    @DeleteMapping("/delete/{userId}/and/{functionId}")
    public Result deleteByUserIdAndFunctionId(@PathVariable("userId") Long userId, @PathVariable("functionId") Long functionId) {
        return feedbackService.deleteByUserIdAndFunctionId(userId, functionId);
    }

}
